<template>
	<view>
		<!-- <u-navbar :is-back="true" :is-fixed="true" title="订单评价"></u-navbar> -->

		<view class="pl-2 pr-3 py-3">
			<view class="dfes">
				<u-image :src="getFullImageUrl(newlist.downAvatar)" border-radius="100rpx"
					style="width: 52px; height: 52px;" @error="handleImageError"></u-image>
				<view class="pl-3 font-14 text-101010">{{newlist.upperEnterpriseName}}</view>
			</view>

			<view class="py-2 pl-2 border-q mt-5 rounded position-relative">
				<textarea name="h" v-model="list.orderEvaluation" id="" placeholder="请输入评价内容" cols="30"
					rows="10"></textarea>
				<div class="char-count font-12 text-A0A0A0 position-absolute right-1">0/150</div>
			</view>
		</view>
		<view style=" background-color:#f7f7f7;" class="dfex">
			<view class="pl-2 pr-2 font-14 lineHight-40 font-weight-bold">{{newlist.productServeName}}</view>
			<view class="pr-2 text-FFC251 font-14">{{newlist.orderState_dictText}}</view>
		</view>
		<ferrButton title="发布评论" @click="submit"></ferrButton>
	</view>
</template>

<script>
	import $H from '@/common/free-lib/request.js';
	import ferrButton from "@/components/free-ui/ferr-button.vue";
	import {
		getImageUrl
	} from '@/common/free-lib/util.js';
	export default {
		components: {
			ferrButton
		},
		data() {
			return {
				list: {
					orderEvaluation: '',
					id: null,
				},
				totalCoun: '',
				newlist: {},
			}
		},
		computed: {
			// charCount() {
			// 	// 计算字符数，不包括空格  
			// 	let noSpaceCount = this.value.replace(/\s+/g, '').length;
			// 	// 计算包含空格的总字符数  
			// 	let totalCount = this.value.length;
			// 	// 返回你想要的格式，这里返回总字符数  
			// 	return `字数: ${totalCount}`;
			// }
		},
		onLoad(options) {
			const id = options.id;
			this.orderEvaluation = options.orderEvaluation;
			this.NewListDetail(id);
			this.id = id;
		},
		methods: {
			handleImageError() {
				uni.showToast({
					title: '图片格式不支持jpeg，请重新上传',
					icon: 'none',
					duration: 4000
				});

			},
			// 拼接图片方法
			getFullImageUrl(imagePath) {
				return getImageUrl(imagePath);
			},
			NewListDetail(id) {
				$H.get('/upper/upperMarketOrder/queryById', {
					id: id
				}, {}).then(res => {
					this.newlist = res.result
				}).catch(error => {
					uni.showToast({
						title: "网络错误，请稍后再试",
						icon: 'none'
					});
				});
			},
			// 提交 
			submit(id) {
				if (!this.list.orderEvaluation) {
					uni.showToast({
						title: '请填写评价',
						icon: 'none',
						duration: 4000
					});
					return;
				}
				const requestData = {
					id: this.id,
					orderEvaluation: this.list.orderEvaluation,
				};
				$H.post('/upper/upperMarketOrder/agriculture/orderEvaluation', requestData, {
					header: {
						'Content-Type': 'application/x-www-form-urlencoded',
					}
				}).then(res => {
					if (res.code === 200) {
						uni.showToast({
							title: res.message || '评论成功',
							icon: 'success',
							duration: 4000
						})
						setTimeout(() => {
							uni.navigateBack({
								delta: 1
							});
						}, 4000);
					} else {
						uni.showToast({
							title: res.message || '评论失败',
							icon: 'none',
						})
					}
				}).catch(error => {
					uni.showToast({
						title: "网络错误，请稍后再试",
						icon: 'none'
					});
				});
			}
		}

	}
</script>

<style lang="scss">
	.char-count {
		bottom: 5px;
	}
</style>